﻿using M6R小圆柱注液机.Data;
using M6R小圆柱注液机.TaskList;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace M6R小圆柱注液机.Pages
{
    public partial class MainPage : Form
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void MainPage_Load(object sender, EventArgs e)
        {
            dgvDataDisp.ColumnCount = 18;
            dgvDataDisp.ColumnHeadersVisible = true;

            string[] name = { "序号", "时间", "条码", "前称", "NO1", "后称", "NO2", "注液量", "OK/NG", "注液针头", "封装压力", "封装温度", "封装时间", "员工工号", "设备编号", "生产型号", "电解液批次号", "弹夹条码" };
            int[] headerLength = { 60, 150, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };
            for (int i = 0; i < name.Length; i++)
            {
                dgvDataDisp.Columns[i].Name = name[i];//设置列名
                dgvDataDisp.Columns[i].Width = headerLength[i];//设置列宽
            }

            //单元格设置
            dgvDataDisp.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//居中
        }

        /// <summary>
        /// 用于数据刷新 - - 前称
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (ProductDataAcq.weightForntDataAll.Count > 0)
            {
                dgvDataDisp.Rows.Insert(0, ProductDataAcq.weightForntDataAll[0].ToArray());//添加数据在datagridview的第一行
                ProductDataAcq.weightForntDataAll.RemoveAt(0);
            }


            if (ProductDataAcq.weightBehindDataAll.Count > 0)
            {
                object[] newData = ProductDataAcq.weightBehindDataAll[0].ToArray();
                for (int i = 0; i < this.dgvDataDisp.Rows.Count; ++i)
                {
                    if (ProductDataAcq.weightBehindDataAll.Count > 0)
                    {
                        if ((string)dgvDataDisp.Rows[i].Cells["条码"].Value == newData[0].ToString())//条码比较
                        {                        
                            this.dgvDataDisp.Rows[i].Cells[5].Value = newData[1];
                            this.dgvDataDisp.Rows[i].Cells[6].Value = newData[2];
                            this.dgvDataDisp.Rows[i].Cells[7].Value = newData[3];
                            this.dgvDataDisp.Rows[i].Cells[8].Value = newData[4];
                            this.dgvDataDisp.Rows[i].Cells[9].Value = newData[5];
                            this.dgvDataDisp.Rows[i].Cells[10].Value = newData[6];
                            this.dgvDataDisp.Rows[i].Cells[11].Value = newData[7];
                            this.dgvDataDisp.Rows[i].Cells[12].Value = newData[8];
                            this.dgvDataDisp.Rows[i].Cells[13].Value = newData[9];
                            this.dgvDataDisp.Rows[i].Cells[14].Value = newData[10];
                            this.dgvDataDisp.Rows[i].Cells[15].Value = newData[11];
                            this.dgvDataDisp.Rows[i].Cells[16].Value = newData[12];
                            this.dgvDataDisp.Rows[i].Cells[17].Value = newData[13];
                            ProductDataAcq.weightBehindDataAll.RemoveAt(0);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }


        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            //if (ProductDataAcq.weightForntDataAll.Count > 0)
            //{
            //    dgvDataDisp.Rows.Insert(0, ProductDataAcq.weightForntDataAll[0].ToArray());//添加数据在datagridview的第一行
            //    ProductDataAcq.weightForntDataAll.RemoveAt(0);
            //}

            //if (ProductDataAcq.weightBehindDataAll.Count > 0)
            //{
            //    object[] newData = ProductDataAcq.weightBehindDataAll[0].ToArray();
            //    for (int i = 0; i < this.dgvDataDisp.Rows.Count; ++i)
            //    {
            //        if (ProductDataAcq.weightBehindDataAll.Count > 0)
            //        {
            //            if ((string)dgvDataDisp.Rows[i].Cells["条码"].Value == newData[1].ToString())//条码比较
            //            {
            //                this.dgvDataDisp.Rows[i].Cells[6].Value = newData[2];
            //                this.dgvDataDisp.Rows[i].Cells[7].Value = newData[3];
            //                this.dgvDataDisp.Rows[i].Cells[8].Value = newData[4];
            //                this.dgvDataDisp.Rows[i].Cells[9].Value = newData[5];
            //                this.dgvDataDisp.Rows[i].Cells[10].Value = newData[6];
            //                this.dgvDataDisp.Rows[i].Cells[11].Value = newData[7];
            //                this.dgvDataDisp.Rows[i].Cells[12].Value = newData[8];
            //                this.dgvDataDisp.Rows[i].Cells[13].Value = newData[9];
            //                this.dgvDataDisp.Rows[i].Cells[14].Value = newData[10];
            //                ProductDataAcq.weightBehindDataAll.RemoveAt(0);
            //            }
            //        }
            //        else
            //        {
            //            return;
            //        }
            //    }
            //}
        }



        public void ReadOnceDataBase()
        {
            //GlobalValues.mysql_Helper.SqlConn(GlobalValues.PathVariable.dataBasePath);//连接数据库

            //string ToDay = DateTime.Now.ToString("yyyy-MM-dd");
            //string startTime = ToDay + " 00:00:00";
            //string endTime = ToDay + " 23:59:59";
            //string sql_Fornt = string.Format("SELECT * FROM `tbforntwight_data` WHERE `时间` BETWEEN '{0}'AND '{1}'", startTime, endTime);
            //string sql_Behind = string.Format("SELECT * FROM `tbbehindweight_data` WHERE `时间` BETWEEN '{0}'AND '{1}'", startTime, endTime);
            //DataSet dt_Fornt = GlobalValues.mysql_Helper.GetDataByPagination(sql_Fornt, 100);
            //DataSet dt_Behind = GlobalValues.mysql_Helper.GetDataByPagination(sql_Behind, 100);
            //DataSet saveDs = new DataSet();
            //for (int i = 0; i < dt_Fornt.Tables.Count; i++)
            //{
            //    dt_Behind.Tables[i].Columns.RemoveAt(0);
            //    dt_Behind.Tables[i].Columns.RemoveAt(0);
            //    //saveDs.Tables.Add(GlobalValues.productInquiryPage.UniteDataTable(dt_Fornt.Tables[i], dt_Behind.Tables[i], i.ToString()));
            //    saveDs.Tables.Add(GlobalValues.productInquiryPage.UniteDataTable(dt_Fornt.Tables[i], dt_Behind.Tables[i], i.ToString()));


            //}

            //for (int i = 0; i < saveDs.Tables.Count - 1; i++)
            //{
            //    for (int j = 0; j < saveDs.Tables[i].Rows.Count; j++)
            //    {
            //        dgvDataDisp.Rows.Insert(0, saveDs.Tables[i].Rows[j].ItemArray);//添加数据在datagridview的第一行
            //    }

            //}









            //GlobalValues.mysql_Helper.SqlClose();//关闭数据库连接
        }




    }
}